﻿using System;
using System.Collections.Generic;
using System.Linq;
using HVACWebService.DataAccese.Entity;

namespace HVACWebService.DataAccese.DataService
{
    public class ShareDeviceDataAccess
    {
        /// <summary>
        /// 添加用户绑定信息
        /// </summary>
        /// <param name="sourceOpenId"></param>
        /// <param name="deviceId"></param>
        /// <param name="ableDeviceId"></param>
        /// <param name="shareOpenId"></param>
        /// <param name="shareCode"></param>
        /// <returns></returns>
        public int CreateShareDevice(string sourceOpenId, string deviceId, string ableDeviceId, string shareOpenId,string shareCode)
        {
            var hvacDatabaseEntities = new HvacDatabaseEntities();

            var shareDevice = new ShareDevice
            {
                SourceOpenId = sourceOpenId,
                DeviceId = deviceId,
                AbleDeviceId = ableDeviceId,
                ShareOpenId = shareOpenId,
                ShareCode = shareCode,
                CreateTime =DateTime.Now
            };
            hvacDatabaseEntities.ShareDevice.Add(shareDevice);
            return hvacDatabaseEntities.SaveChanges();
        }


        /// <summary>
        /// 获得设备分享信息
        /// </summary>
        /// <param name="openId"></param>
        /// <param name="deviceId"></param>
        /// <returns></returns>
        public List<ShareDevice> GetShareDeviceByOpenIdAnd(string openId,string deviceId)
        {
            var hvacDatabaseEntities = new HvacDatabaseEntities();
            return hvacDatabaseEntities.ShareDevice.Where(cd => cd.ShareOpenId == openId && cd.DeviceId == deviceId).ToList();
        }

    }
}